package com.wl.controller;

import com.wl.dto.FunctionAddDto;
import com.wl.entity.FunctionTree;
import com.wl.service.FunctionTreeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("test")
public class TestController {

    @Resource
    private FunctionTreeService functionTreeService;
    @PostMapping("update/{parentId}")
    public int updateTree(@PathVariable("parentId") Long parentId, @RequestBody List<FunctionTree> trees){
        return functionTreeService.updateTree(parentId,trees);
    }


    @PostMapping("add")
    public int add(@RequestBody FunctionAddDto dto){
        return functionTreeService.addTree(dto.getParentId(), dto.getName());
    }

    @GetMapping("tree")
    public List<FunctionTree> tree(){
        return functionTreeService.tree();
    }

    @GetMapping("query")
    public List<FunctionTree> query(String name){
        return functionTreeService.query(name);
    }
}
